package com.efounder.presenter;

import com.efounder.activity.MallWinTreasureDetailsActivity;
import com.efounder.bean.WinTreasureDetailsBean;
import com.efounder.mobilemall.R;
import com.efounder.util.LoadingDataUtilBlack;
import com.efounder.utils.MallRequestUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.efounder.mvp.base.BasePresenterImpl;
import com.utilcode.util.ToastUtils;

import java.util.HashMap;

import static com.efounder.utils.MallRequestUtil.MALL_TREASURE_ORDER_DETAILS;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/11/5 9:07
 * @desc :  夺宝详情页的presenter
 * @version: 1.0
 */
public class MallWinTreasureDetailsPresenter extends BasePresenterImpl<MallWinTreasureDetailsActivity> {

    public MallWinTreasureDetailsPresenter(MallWinTreasureDetailsActivity view) {
        super(view);
    }

    /**
     * 获取详情页中的数据
     * @return
     */
    public void  getWinTreasureDetailsBean(String mallGoodsId){
        //?mallGoodsId=20181105
        LoadingDataUtilBlack.show(mContext);
        HashMap<String,String> map = new HashMap<>();
        map.put("mallGoodsId",mallGoodsId);
        MallRequestUtil.getRequest(TAG, MALL_TREASURE_ORDER_DETAILS, map, new MallRequestUtil.MallRequestCallback() {
            @Override
            public void onSuccess(String response) {
                LoadingDataUtilBlack.dismiss();
                if(view!=null){
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    WinTreasureDetailsBean winTreasureDetailsBean = gson.fromJson(response,WinTreasureDetailsBean.class);
                    if(winTreasureDetailsBean!=null){
                        if(winTreasureDetailsBean.getCode() == 0){
                            view.getWinTreasureDetailsBeanDataSuccess(winTreasureDetailsBean);
                        }else {
                            view.getWinTreasureDetailsBeanDataFails();
//                            ToastUtils.showShort(winTreasureDetailsBean.getMsg());

                        }
                    }else {
                        ToastUtils.showShort(mContext.getString(R.string.mail_get_data_fail_again));
                    }

                }

            }

            @Override
            public void onFail(String error) {
                LoadingDataUtilBlack.dismiss();
                ToastUtils.showShort(mContext.getString(R.string.mail_get_data_fail_again));
            }
        });

    }
}
